package cn.darkhorse.mesadmin.controller.device;


import cn.darkhorse.device.pojo.MesMsgWarning;
import cn.darkhorse.device.service.MesMsgWarningService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 业务提醒 前端控制器
 * </p>
 *
 * @author maoguanjun
 * @since 2023-02-07
 */
@RestController
@RequestMapping("/device/mesMsgWarning")
public class MesMsgWarningController extends BaseController {
    @Resource
    private MesMsgWarningService mesMsgWarningService;

    /**
     * 列表
     * @param deviceName
     * @param beginTime
     * @param endTime
     * @param userId
     * @param readFlag
     * @return
     */
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    public TableDataInfo list(String deviceName,String beginTime,String endTime,Long userId,Integer msgType,Integer readFlag){
        if(null==readFlag){
            readFlag=0;
        }
        startPage();
        List<MesMsgWarning> list = mesMsgWarningService.listAll(deviceName,beginTime,endTime,userId,msgType,readFlag);
        return getDataTable(list);
    }

    /**
     * 获取数量
     * @param deviceName
     * @param beginTime
     * @param endTime
     * @param userId
     * @param readFlag
     * @return
     */
    @RequestMapping(value = "/count",method = RequestMethod.POST)
    public AjaxResult count(String deviceName, String beginTime, String endTime, Long userId,Integer msgType, Integer readFlag){
        if(null==readFlag){
            readFlag=0;
        }
        Long count = mesMsgWarningService.count(deviceName,beginTime,endTime,userId,msgType, readFlag);
        return AjaxResult.success(count);
    }

    /**
     * 更新为已读
     * @param id
     * @return
     */
    @RequestMapping(value = "/read",method = RequestMethod.POST)
    public AjaxResult read(Long id){
        if(null==id){
            AjaxResult.error("缺失参数！");
        }
        boolean result=mesMsgWarningService.read(id);
        return AjaxResult.success(result) ;
    }
}

